//
//  UIButton+Extension.swift
//  Mircoblog-swift
//
//  Created by zz on 16/2/24.
//  Copyright © 2016年 zz. All rights reserved.
//

import UIKit

extension UIButton{
 /// 创建 UIButton
    convenience init(zd_title title: String?,
                fontSize: CGFloat = 17,
                color: UIColor = UIColor.darkGrayColor(),
                imageName: String?=nil,
                backImageName: String?=nil
                ) {
                    
                    self.init()
        self.setTitle(title, forState: .Normal)
        self.setTitle(title, forState: .Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        self.setTitleColor(color, forState: .Normal)
        
        if let imageName = imageName {
            self.setImage(UIImage(named: imageName), forState: .Normal)
            self.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        }
        
        if let backImageName = backImageName {
            self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            self.setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        }
        
        // 让按钮根据背景图片调整大小
        sizeToFit()
        
    }
    
}